package com.controller;

import com.bean.OrderDetailet;
import com.common.R;
import com.service.OrderDetailetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//依旧是三个或两个注解
@Controller
@ResponseBody
//@RestController
@RequestMapping("/OrdersDetailetController")
@CrossOrigin
public class OrdersDetailetController {
    @Autowired
    private OrderDetailetService orderDetailetService;


    @PostMapping("/saveOrderDetailetBatch")
    private R saveOrderDetailetBatch(List<OrderDetailet> orderDetailet){
        try {
            int i = orderDetailetService.saveOrderDetailetBatch(orderDetailet);
            if (i>0){
                return R.ok().msg("保存成功");
            }else {
                return R.error().msg("保存失败");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    @PostMapping("/listOrderDetailetByOrderId")
    private R listOrderDetailetByOrderId(@RequestBody OrderDetailet orderDetailet){
        try {
            return R.ok().data(orderDetailetService.listOrderDetailetByOrderId(orderDetailet.getOrderId()));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
